﻿using Liuliu.ScriptEngine;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using System.Xml.Linq;

namespace GmControlTools
{
    public class Startup
    {
        
        public void ConfigureServices(IServiceCollection services)
        {
            // 添加框架提供的服务
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // 配置请求管道
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseStaticFiles();
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/Get", async (HttpContext context, string name) =>
                {
                    string result = TaskHandler.StartTask(2, "测试发送公告", 0, "") ? "成功" : "失败";
                    await context.Response.WriteAsync($"Hello,下线{name}{result}!");
                    
                });
                endpoints.MapPost("/OfflineUser", async context =>
                {
                    var form = await context.Request.ReadFormAsync();
                    string userName = form["username"].ToString();
                    string response = $"下线玩家: {userName}";
                    //string result = TaskHandler.StartTask(1, "德玛西亚", 0, "") ? "成功" : "失败";
                    TaskModle task = new TaskModle
                    {
                        actionType = 1,
                        NameOrContent = userName
                    };
                    TaskHandler.Instance.AddQueue(task);
                    await context.Response.WriteAsync($"200");
                });
                endpoints.MapPost("/SendNotice", async context =>
                {
                    string content = context.Request.Form["content"];//公告内容
                    string response = $"发送公告: {content}";
                    TaskModle task = new TaskModle
                    {
                        actionType = 2,
                        NameOrContent = content
                    };
                    TaskHandler.Instance.AddQueue(task);
                    await context.Response.WriteAsync($"200");
                });
            });
        }

        
    }
}
